<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://www.ccut.edu.cn/saturn" prefix="saturn"%>
<%@page import="edu.ccut.saturn.component.SaturnDebugThreadsManager"%>
<%@page import="java.util.*"%>
<%@page import="edu.ccut.saturn.component.IDebugThread"%>
<%@page import="edu.ccut.saturn.component.IParameterInfo"%>
<%@ include file="/extjs/include/all.jsp" %>
<script>
var urlpath="<%=request.getContextPath()%>";
</script>
<script type="text/javascript" src="js/browser.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/dhtmlxcommon.js"></script>
<script type="text/javascript" src="js/dhtmlxtree.js"></script>
<html>
<head>
<title>Saturn Debug</title>
<style type="text/css">
.showDiv {
	color: graytext;
	position: relative;
	top: 200px;
	left: 50%;
	height: 25px;
}
</style>
</head>
<body>
	<div id="north"><div id="toolbar"></div></div>
	<div id="center"></div>
	<div id="south"></div>
	<div id="west" style="height: 100%"></div>
<%
			request.setAttribute("treeList", SaturnDebugThreadsManager
			.getInstance().getOverDebugThreadTreeList());
			
			Map scopeMap = (Map)session.getAttribute("debug_saturn_scope");
			if (scopeMap == null) {
				scopeMap = new HashMap();
				scopeMap.put(IParameterInfo.SCOPE_LOGIC , "logic");
				scopeMap.put(IParameterInfo.SCOPE_REQUEST, "request");
				scopeMap.put(IParameterInfo.SCOPE_SESSION, "session");
				scopeMap.put(IParameterInfo.SCOPE_APPLICATOIN, "application");
				
				session.setAttribute("debug_saturn_scope", scopeMap);
			} 
			
			Map inoutMap = (Map)session.getAttribute("debug_saturn_in_out");
			if (inoutMap == null) {
				inoutMap = new HashMap();
				inoutMap.put(IParameterInfo.PASSING_IN, "输入");
				inoutMap.put(IParameterInfo.PASSING_OUT, "输出");
				inoutMap.put(IParameterInfo.PASSING_IN_OUT, "输入输出");
				inoutMap.put(IParameterInfo.PASSING_UNDEFINE, "未定义");
				
				session.setAttribute("debug_saturn_in_out", inoutMap);
			}
%>
<script>
function noneShow(){
document.getElementById("showInfo").innerText="";
}
setTimeout("noneShow()",2000);
</script>
<%if(request.getAttribute("succ")!=null){%>
<div id="showInfo" class="showDiv"><img
	src="<%=request.getContextPath() %>/edu.ccut.saturn.manager.debug.impl/extDebugModule/page/images/loading.gif" />&nbsp;&nbsp;<%=request.getAttribute("succ")%></div>
<%}else{%>
<div class="showDiv" id="showInfo">&nbsp;&nbsp;</div>
<%}%>

	<div id='treeDiv' style="width: 210px; position:relative;top:15px; overflow:auto;">
		<saturn:tree id="tree1" target="detail" nodeIdKey="id"
			nodeParentIdKey="parentId" nodeLabelKey="name"
			nodeCheckableKey="checkable" nodeExpandedKey="expanded"
			nodeExpandedIconKey="expandedIcon" nodePathKey="path"
			nodeIconKey="icon" value="${treeList}" />
	</div>
<%
System.out.println("-----------------------treeList------------------------"); 
System.out.println(session.getAttribute("treeList")); 
System.out.println(request.getAttribute("treeList")); 
System.out.println(application.getAttribute("treeList")); 
System.out.println("-------------------------------------------------------"); 
%>
</body>
</html>
<script>

Ext.onReady(function() {  

		var debugTree = new Ext.tree.TreePanel({
			title:'调试',
			id:'debug-tree',
			autoScroll:true,
			enableDD:false,
			containerScroll: true,
			rootVisible:false,
			loader:new Ext.tree.TreeLoader({
				dataUrl:'<%=request.getContextPath()%>/edu.ccut.saturn.manager.debug.impl::/extDebugModule/action/GetTreeJson.action'
			})
		});
		
		var treeRootNode = new Ext.tree.AsyncTreeNode({
			text:'根节点',
			id:'saturn-tree-root'
		});
		
		debugTree.setRootNode(treeRootNode);
		debugTree.on('click', function(node) {
				
				debugTreeClick(node.attributes.path);
		}, this);
		
		function debugTreeClick(path) {		

			Ext.get('detail').dom.src = path;
		}
		
	   	var saturnMain = new Ext.Viewport({
	        layout:'border',
			items:[
				new Ext.BoxComponent({ 
					region:'north',
					el: 'north',
					margins:'5',
					height:30
				}),{	
					region:'west',
					//title:'debug信息',
					collapsible:true,
					split:true,
					width:225,
					minSize:175,
					maxSize:400,
					layout:'fit',
					margins:'0 0 0 5',
					items:debugTree
				},{
					id:"saturn-panel",
	                region:'center',
	                items:[{
	                    title: 'Debug',
	                    autoScroll:true, 
	                    autoHeight:true,
	                    html:'	<iframe frameborder="0" id="detail" name="detail" width="100%" height="100%" scrolling="auto" src=""></iframe>'
	                }]
	            }
			]
		});
		document.getElementById('tree1').style.height = Ext.get('west').getHeight();
		document.getElementById('tree1').style.width = 200;
		document.getElementById('detail').style.height = Ext.get('west').getHeight() - 40;
		function saturnCreateMenuToolbar() {
			var tb = new Ext.Toolbar();    
			tb.render('toolbar');
			tb.add({
				id: 'start', 
				text: '开始',
				scope: this,
				handler: function(bar) {
					window.location='start.jsp';
				}
			});
			tb.add({
				id: 'stop', 
				text: '停止',
				scope: this,
				handler: function(bar) {
					window.location='end.jsp';
				}
			});
			tb.add({
				id: 'clear', 
				text: '清空',
				scope: this,
				handler: function(bar) {
					window.location='clear.jsp';
				}
			});
			tb.add({
				id: 'refresh', 
				text: '刷新',
				scope: this,
				handler: function(bar) {
					window.location='index.jsp';
				}
			});
		}
		saturnCreateMenuToolbar();
});
</script>